﻿<catel:DataWindow x:Class="Catel.Examples.AdvancedDemo.Views.BehaviorsWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
				  xmlns:catel="http://catel.codeplex.com"
                  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">

    <!-- Resources -->
    <catel:DataWindow.Resources>
        <catel:BooleanToCollapsingVisibilityConverter x:Key="BooleanToCollapsingVisibilityConverter" />
    </catel:DataWindow.Resources>

    <!-- Content -->
    <catel:StackGrid x:Name="behaviorsRootStackGrid">
        <catel:StackGrid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </catel:StackGrid.RowDefinitions>

        <catel:StackGrid.ColumnDefinitions>
            <ColumnDefinition Width="400" />
            <ColumnDefinition Width="400" />
        </catel:StackGrid.ColumnDefinitions>

        <GroupBox Header="DelayBindingUpdate">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                        Change a value and the value will update one second later.
                    </TextBlock>
                </Label>

                <ListBox ItemsSource="1234" SelectedItem="{Binding DelayBindingUpdateValue}">
                    <i:Interaction.Behaviors>
                        <catel:DelayBindingUpdate PropertyName="SelectedItem" UpdateDelay="1000" />
                    </i:Interaction.Behaviors>
                </ListBox>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="DoubleClickToCommand">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                        Double click the image below.
                    </TextBlock>
                </Label>

                <Image Source="/Resources/Images/catel.png" Width="32" Height="32"
                       HorizontalAlignment="Center" VerticalAlignment="Center">
                    <i:Interaction.Behaviors>
                        <catel:DoubleClickToCommand Command="{Binding DoubleClickToCommandExample}" />
                    </i:Interaction.Behaviors>
                </Image>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="EventToCommand">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                    This behavior shows a message box when the 'LostFocus' event occurs in the calender.
                    </TextBlock>
                </Label>

                <Calendar>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="LostFocus">
                            <catel:EventToCommand Command="{Binding EventToCommandForLostFocus}" DisableAssociatedObjectOnCannotExecute="False" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Calendar>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="Focus">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                        Note that when the window is loaded, the TextBox below has the focus
                    </TextBlock>
                </Label>

                <TextBox Text="Focus is here when the control is loaded">
                    <i:Interaction.Behaviors>
                        <catel:Focus FocusMoment="Loaded" />
                    </i:Interaction.Behaviors>
                </TextBox>

                <TextBox Text="Focus on event, on MouseEnter of this TextBox" x:Name="mouseEnterTextBox">
                    <i:Interaction.Behaviors>
                        <catel:Focus FocusMoment="Event" EventName="MouseEnter" Source="{Binding ElementName=mouseEnterTextBox}" />
                    </i:Interaction.Behaviors>
                </TextBox>

                <TextBox Text="Focus on property changed, when ListBox value has changed">
                    <i:Interaction.Behaviors>
                        <catel:Focus FocusMoment="PropertyChanged" PropertyName="DelayBindingUpdateValue" Source="{Binding }" />
                    </i:Interaction.Behaviors>
                </TextBox>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="KeyPressToCommand">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                        The 'KeyPressToCommandExample' command will be executed when the [Ctrl] + [Backspace] keys are pressed on the ListBox.
                    </TextBlock>
                </Label>

                <ListBox ItemsSource="1234">
                    <i:Interaction.Behaviors>
                        <catel:KeyPressToCommand Command="{Binding KeyPressToCommandExample}" Key="Back" Modifiers="Control" />
                    </i:Interaction.Behaviors>
                </ListBox>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="MouseInfo">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                    <i:Interaction.Behaviors>
                        <catel:MouseInfo x:Name="mouseInfo" />
                    </i:Interaction.Behaviors>                    
                    
                    Hover this text to show the ListBox.
                    </TextBlock>
                </Label>

                <ListBox ItemsSource="1234" Visibility="{Binding ElementName=mouseInfo, Path=IsMouseOver, Converter={StaticResource BooleanToCollapsingVisibilityConverter}}" />
            </StackPanel>
        </GroupBox>

        <GroupBox Header="NumericTextBox">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                    This textbox only allows numeric characters. The allowed characters can be fully customized.
                    </TextBlock>
                </Label>

                <TextBox>
                    <i:Interaction.Behaviors>
                        <catel:NumericTextBox />
                    </i:Interaction.Behaviors>
                </TextBox>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="SelectTextOnFocus">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                    When the TextBox receives the focus, all text is selected.
                    </TextBlock>
                </Label>

                <TextBox Text="All text should be selected">
                    <i:Interaction.Behaviors>
                        <catel:SelectTextOnFocus />
                    </i:Interaction.Behaviors>
                </TextBox>
            </StackPanel>
        </GroupBox>

        <GroupBox Header="UpdateBindingOnTextChanged">
            <StackPanel Orientation="Vertical">
                <Label>
                    <TextBlock TextWrapping="Wrap">
                    Type the textbox and see the binding update happening after 500 ms when the user stops typing.
                    </TextBlock>
                </Label>

                <TextBox Text="{Binding UpdateBindingOnTextChangedValue, Mode=TwoWay}">
                    <i:Interaction.Behaviors>
                        <catel:UpdateBindingOnTextChanged UpdateDelay="500" />
                    </i:Interaction.Behaviors>
                </TextBox>

                <TextBlock Text="{Binding UpdateBindingOnTextChangedValue}" />
            </StackPanel>
        </GroupBox>

    </catel:StackGrid>
</catel:DataWindow>
